<?php

/**
 * This is the model class for table "{{gear}}".
 *
 * The followings are the available columns in table '{{gear}}':
 * @property integer $id
 * @property string $l3
 * @property string $l4
 * @property string $l4_code
 * @property string $l5
 * @property string $metier_code
 * @property string $biomar_code
 *
 * The followings are the available model relations:
 * @property Trip[] $trips
 */
class Gear extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Gear the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{gear}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('l3, l4, l4_code, l5, metier_code, biomar_code', 'required'),
			array('l3', 'length', 'max'=>20),
			array('l4, l5', 'length', 'max'=>40),
			array('l4_code', 'length', 'max'=>10),
			array('metier_code, biomar_code', 'length', 'max'=>30),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, l3, l4, l4_code, l5, metier_code, biomar_code', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'trips' => array(self::HAS_MANY, 'Trip', 'gear_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'l3' => 'L3',
			'l4' => 'L4',
			'l4_code' => 'L4 Code',
			'l5' => 'L5',
			'metier_code' => 'Metier Code',
			'biomar_code' => 'Biomar Code',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('l3',$this->l3,true);
		$criteria->compare('l4',$this->l4,true);
		$criteria->compare('l4_code',$this->l4_code,true);
		$criteria->compare('l5',$this->l5,true);
		$criteria->compare('metier_code',$this->metier_code,true);
		$criteria->compare('biomar_code',$this->biomar_code,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}